package controller

/**
 * e.g
 * path = /activities/{activityId}/joiners/{userId}
 *  want to get {activityId}
 *  need to set prePath = activities/ or /activities/
 * PS: in path, prePath can not appear twice or more
 */
fun getIdFromPath(path: String, prePath: String): Int {
    val index = path.indexOf(prePath)
    val len = prePath.length
    var id = -1
    if (index > -1) {
        var end = path.indexOf('/', index + len)
        if (end == -1) {
            end = path.length
        }
        id = Integer.parseInt(path.substring(index + len, end))
    }
    return id
}